package com.doria.common.pojo.vo;

import com.doria.common.ad_enum.CodeEnum;
import com.doria.common.ad_enum.MsgEnum;
import com.doria.common.pojo.basic.UserThreadLocal;
import com.doria.common.pojo.po.User;
import lombok.*;

@Getter
@Setter
public class HttpResult {

    private boolean flag;
    private Integer code;
    private String msg;
    private Object object;

    // 空参构造
    public HttpResult() {

    }

    public void setCode(CodeEnum codeEnum) {
        this.code = codeEnum.getCode();
    }

    public void setMsg(MsgEnum msgEnum) {

        User user = UserThreadLocal.getDefaultUser();
        this.msg="cn".equals(user.getLanguage())?msgEnum.getCn():msgEnum.getEn();
    }

    // 无返回值
    public HttpResult(boolean flag, CodeEnum httpCodeEnum, MsgEnum msgEnum) {
        User user = UserThreadLocal.getDefaultUser();
        this.flag = flag;
        this.code = httpCodeEnum.getCode();
        this.msg="cn".equals(user.getLanguage())?msgEnum.getCn():msgEnum.getEn();
    }

    // 有返回值
    public HttpResult(boolean flag, CodeEnum httpCodeEnum, MsgEnum msgEnum, Object object) {
        User user = UserThreadLocal.getDefaultUser();
        this.flag = flag;
        this.code = httpCodeEnum.getCode();
        this.msg="cn".equals(user.getLanguage())?msgEnum.getCn():msgEnum.getEn();
        this.object=object;
    }
}
